package  com.pcbly.web.business.crm;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.crm.YkckDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.crm.YkckBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class YkckServiceImp extends BaseServiceImp<YkckBean> implements YkckService {
	 public YkckServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private YkckDao ykckDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setYkckDao(YkckDao ykckDao) {
		this.ykckDao = ykckDao;
	}
	
	@Override
	public YkckBean getYkckBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return ykckDao.get(YkckBean.class,id);
	}
	
	@Override
	public void removeYkckBeanById(String id) throws Exception{
		ykckDao.removeYkckBeanById(id);
	}
	
	@Override
	public void removeYkckBeanByIds(String ids) throws Exception{
		ykckDao.removeYkckBeanByIds(ids);
	}
	
	
	@Override
	public YkckBean saveYkckBean(YkckBean crm) throws Exception{
		return ykckDao.saveYkckBean(crm);
	}
	
	@Override
	public YkckBean updateYkckBean(YkckBean crm) throws Exception{
		ykckDao.saveObject( crm);
		return crm;
	}
	public Page<YkckBean>  findYkckBeanByCond(YkckBean bean,
			Page<YkckBean> page, String orderByName, boolean asc)
			throws Exception{
		return ykckDao.findYkckBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findYkckBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findYkckBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = ykckDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findYkckBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = ykckDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveYkckBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		ykckDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasYkckBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return ykckDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
